package com.ticket.sass.common.douyin.openapi

import com.google.gson.Gson
import com.google.gson.GsonBuilder
import com.google.gson.reflect.TypeToken
import com.ticket.sass.common.douyin.openapi.enums.CertificateStatus
import com.ticket.sass.common.douyin.openapi.enums.GoodsStatus
import com.ticket.sass.common.douyin.openapi.enums.UniversalEnumDeserializer
import com.ticket.sass.common.douyin.openapi.resposne.ApiResponse
import com.ticket.sass.common.douyin.openapi.resposne.QueryCodeStatus
import org.junit.jupiter.api.Test
import org.slf4j.LoggerFactory
import java.net.URLEncoder
import java.nio.charset.StandardCharsets

class ClientTest {
    @Test
    fun test() {

        val client =
            Client("aw7e1j4oaogzuoz3", "172a6daf20074a1b1bba290813b528b2", "", "")
        val createTokenResult = client.createClientToken()
        client.setLogger(LoggerFactory.getLogger("test")!!)
//        ApiResponse(data={access_token=clt.c8bca1e5a6dd8cb2aa2c89d21628337fbc53dSTELPv6UGZX7ClFWx5T7doW_lf, captcha=, desc_url=, description=, error_code=0.0, expires_in=7200.0, log_id=20240719095448C501E8CD63046472BAB1}, message=success, extra=null)
        client.setAccessToken(createTokenResult.accessToken!!)
        val result = client.listGoods(
            Client.ListGoodsQry(
                count = 50,
                status = GoodsStatus.DISABLED,
            )
        )
        println(Gson().toJson(result))
//        echo(result)
//        var r = client.shortUrlToLongUrl("https://v.douyin.com/eHHc1ft/")
//        println(r)
//        val result = client.verifyCouponPrepare("https://v.douyin.com/iMAHHGVC/")
//        println(result)
//        if (result.certificates.isEmpty()) {
//            println("no certificate")
//            return
//        }
//        println(Gson().toJson(result))

//        val verifyResult =
//            client.verifyCoupon(result.verifyToken!!, result.certificates!!.map { it.encryptedCode })
//        val r = Gson().toJson(verifyResult)
//        println(r)

    }

    fun echo(data: Any) {
        val r = Gson().toJson(data)
        println(r)
    }

}